TFastFourier component

Properties	Methods	Events	Example1 	Example2	Example3

TFastFourier is a component representing the Fast Fourier Transformation for discrete quadratic approximation of periodic functions. The transformed spectrum can be cut - both low and high - and cleaned from error. The cut and noise-cleaned spectrum can then be inverted to reproduce the original, error-cleaned data.

Using the component

The OnGetValue property is the virtual data input of the component and is called whenever the component needs data. The Length property defines the numbers of the equidistant points of the periodic function to be transformed.

After calling the DoFourier method, the Fourier array property gives access to the transformed data containing complex numbers. The Spectrum property array contains the spectrum of transformed data.

Manipulating the transformed function

The LowCut and HighCut properties allow you to cut data falling into the upper and/or lower part of the frequency spectrum. The Noise property determines the level of noise to cut data under it. It can be used to reduce noise when the input has random errors. With the Transformed array property you can easily access the noise-cleaned and cut data and the TransformedSpectrum property array contains the spectrum of this data.

After noise reduction and cutting you can call the DoInverse method to create the function that the current data (in the Transformed property array) represents and access its data through the Inverse property array.


Properties

Fourier	Noise
HighCut	Spectrum
Inverse	Transformed
Length	TransformedSpectrum
LowCut


Methods

DoFourier

DoInverse


Events

OnGetValue


Fourier property

Applies to

TFastFourier component

Declaration

property Fourier[Index: Word; ComplexPart: TComplexNumPart]: Double;

Description

The Fourier array property gives access to the array of complex numbers that are the results of the DoFourier method. Index is the index of the data and it must be between 1 and the value of the Length property. You can specify which part of the complex number you wish to get by setting the value of ComplexPart to cpRe or cpIm, respectively. The property is read only, so you can access and analyze the data directly, but cannot modify it.

See Also

DoFourier, Length


HighCut property

Example

Applies to

TFastFourier component

Declaration

property HighCut: TDouble;

Description

The data transformed by Fast Fourier Transformation can be cut. The HighCut property specifies a percentage of the spectrum to be cut from the highest frequency. Data falling into the specified range of the spectrum will be cleared. The value of 0 cuts no data. The value of 25, for example, means that data falling into the upper 25% of the spectrum is truncated. In voice processing, this operation removes the higher frequencies from the sound.

See Also

DoInverse, LowCut, Noise, Transformed


Inverse property

Example

Applies to

TFastFourier component

Declaration

property Inverse[Index: Word; ComplexPart: TComplexNumPart]: Double;

Description

The Inverse array property contains the data cut and cleaned by noise and then transformed back by Inverse Fourier Transformation. Index is the index of the data and it must be between 1 and Length. You can specify which part of the complex number you wish to get by setting the value of ComplexPart to cpRe or cpIm, respectively. The property is read only.

See Also

DoInverse, Transformed


Length property

Example

Applies to

TFastFourier component

Declaration

property Length Word;

Description

The Length property determines the numbers of the input data. Length must be a power of 2. There is no limitation on the Length property but a memory exception occurs if there is not enough memory to store the data for transformation. The memory needed by the component is Length x 2 x 16 bytes.

The Length property gives the upper limit for the indexes of the Fourier, Transformed and Inverse property arrays.

See Also

Fourier, Transformed, Inverse


LowCut property

Example

Applies to

TFastFourier component

Declaration

property LowCut: Double;

Description

The data transformed by Fast Fourier Transformation can be cut. The LowCut property specifies a percentage of the spectrum to be cut from the lowest frequency. Data falling into the specified range of the spectrum will be cleared. The value of 0 cuts no data. The value of 25, for example, means that data falling into the lower 25% of the spectrum is truncated. In voice processing, this operation removes the low frequencies from the sound.

See Also

DoInverse, HighCut, Noise, Transformed


Noise property

Example

Applies to

TFastFourier component

Declaration

property Noise: Double;

Description

The data transformed by Fast Fourier Transformation can be cleared from noise. The Noise property specifies the cutting level. Data falling into spectrums having an amplitude lower than Noise will be cleared. (The minimum and maximum amplitude depends on the input data.) The value of 0 cuts no data. The value of 250, for example, removes all frequency spectrums whose amplitude is less than 250. In voice processing, this operation removes the non-important frequencies (usually noise) from the sound.

See Also

DoInverse, HighCut, LowCut, Transformed


Spectrum property

Example

Applies to

TFastFourier component

Declaration

property Spectrum[Index: Word]: Double;

Description

The Spectrum property array contains the frequency spectrum of the data transformed by the DoFourier method. The first Length/2 items contain the spectrums, so the possible value of Index is between 1 and Length div 2. The property is read only.

See Also

DoFourier, TransformedSpectrum


Transformed property

Example

Applies to

TFastFourier component

Declaration

property Transformed[Index: Word; ComplexPart: TComplexNumPart]: Double;

Description

The Transformed array property contains the transformed data cut and cleaned by noise. The DoInverse method uses this array as its input. Index must be between 1 and Length. You can specify which part of the complex number you wish to get by setting the value of ComplexPart to cpRe or cpIm, respectively. The property is read only.

See Also

DoInverse, HighCut, LowCut, Noise, TransformedSpectrum


TransformedSpectrum property

Example

Applies to

TFastFourier component

Declaration

property TransformedSpectrum[Index: Word]: Double;

Description

The TransformedSpectrum property array contains the frequency of the data transformed by DoFourier and cut and cleared from error using the LowCut, HighCut and Noise properties. If LowCut, HighCut and Noise are all 0, this array is equivalent to the Spectrum property array. The property is read only.

See Also

DoInverse, HighCut, LowCut, Noise, Transformed, Spectrum


DoFourier method

Example

Applies to

TFastFourier component

Declaration

procedure DoFourier;

Description

The DoFourier method runs the Fast Fourier Transformation on the input data. The Fourier and Spectrum properties can then be used to access the transformed data.

See Also

DoInverse, Fourier, Spectrum


DoInverse method

Example

Applies to

TFastFourier component

Declaration

procedure DoInverse;

Description

The DoInverse method runs the Inverse Fast Fourier Transformation on the data transformed by DoFourier and cut and cleaned from noise by using the LowCut, HighCut and Noise properties. The Transformed property array contains the input of DoInverse.

See Also

DoFourier, Transformed, Fourier, HighCut, LowCut, Noise


OnGetValue property

Example

Applies to

TFastFourier component

Declaration

TFFTGetValue = procedure(Sender: TObject;Index: Word; ComplexPart: TComplexNumPart;var Value: Double) of object;

property OnGetValue: TFFTGetValue;

Description

The OnGetValue event is the virtual data input for the TFastFourier component. This event occurs whenever the component needs data during executing the DoFourier method. The value Index shows which point of the function is required. Its possible value is between 1 and Length.

ComplexPart specifies which part of the complex number the algorithm needs. Its value can be cpRe or cpIm, respectively. For normal functions, the imaginary part should be 0, so when ComplexPart is cpIm, you should return 0 in Value. (The component is also capable to transform complex functions and that’s when ComplexPart comes into play.)

See Also

DoFourier, Length


Example: Handling the OnGetValue event

// This example shows how to handle the OnGetValue event

// to provide data to the component. TRadioGroup named

// RadioGroupInitData determines the type of init function.

procedure TFormMain.FastFourier1GetValue(Sender: TObject; Index: Word;

  ComplexPart: TComplexNumPart; var Value: Double);

begin

  case RadioGroupInitData.ItemIndex of

    0: //  Sum of two sinus waves with random noise

      if ComplexPart = cpRe then

        Value := 0.45 * sin(Index/10) + 0.35*sin(Index) + 0.4 * Randoms[Index]

      else

        Value := 0;

    1: //  Triangular wave form with random noise

      if ComplexPart = cpRe then

        if (Index mod 40)>19 then

          Value := (1 - (Index mod 20)/10)*0.9+0.2*Randoms[Index]

        else

          Value := ((Index mod 20)/10-1)*0.9+0.2*Randoms[Index]

      else

        Value := 0;

    2: //  Rectangular wave form with random noise

      if ComplexPart = cpRe then

        if (Index mod 40)>19 then

          Value := -0.9+0.2*Randoms[Index]

        else

          Value := 0.9+0.2*Randoms[Index]

      else

        Value := 0;

    3: //  Another triangular wave form with random noise

      if ComplexPart = cpRe then

        Value := ((Index mod 20)/10-1)*0.9+0.2*Randoms[Index]

      else

        Value := 0;

  end;

end;


Example: Setting the main properties

// This example shows how to use Length, HighCut, LowCut,

// and Noise properties to cut off some frequencies.

// Length must be the power of 2. After setting the properties

// you must call the DoFourier and DoInverse methods before

// accessing the Fourier, Transformed and Inverse property arrays

procedure TFormMain.ResetValues;

begin

  FastFourier1.Length := 128;

  FastFourier1.DoFourier;

  FastFourier1.HighCut := 0;

  FastFourier1.LowCut := 0;

  FastFourier1.Noise := 10;

  FastFourier1.DoInverse;

end;


Example: Using Inverse, Spectrum and TransformedSpectrum

//  This example draws four charts to show the difference between

//  the original and cut input function and the spectrum values.

procedure TFormMain.PaintBoxesPaint(Sender: TObject);

var

  x,y,i: LongInt; value: Double;

begin

  x := PaintBox1.Width div FastFourier1.Length;

  w := x;

  for i := 1 to FastFourier1.Length div 2 do begin

    y := Round(PaintBox1.Height - PaintBox1.Height*FastFourier1.Spectrum[i]);

    PaintBox1.Canvas.Rectangle(x,y,x+w,PaintBox1.Height);

    y := Round(PaintBox1.Height div 2 - PaintBox1.Height*FastFourier1.TransformedSpectrum[i]);

    PaintBox1.Canvas.Rectangle(x,y,x+w,PaintBox1.Height div 2);

    x := x + w;

  end;

  FastFourier1GetValue(self,1,cpRe,Value);

  x := Round(PaintBox2.Width/FastFourier1.Length);

  y := Round(PaintBox2.Height/2 + PaintBox2.Height/2*Value);

  PaintBox2.Canvas.MoveTo(x,y);

  for i := 2 to FastFourier1.Length do begin

    FastFourier1GetValue(self,i,cpRe,value);

    x := Round(PaintBox2.Width/FastFourier1.Length*i);

    y := Round(PaintBox2.Height/2 + PaintBox2.Height/2*Value);

    PaintBox2.Canvas.LineTo(x,y);

  end;

  x := Round(PaintBox2.Width/FastFourier1.Length);

  y := Round(PaintBox2.Height/2 + PaintBox2.Height/2*FastFourier1.Inverse[1,cpRe]);

  PaintBox2.Canvas.MoveTo(x,y);

  for i := 2 to FastFourier1.Length do begin

    x := Round(PaintBox2.Width/FastFourier1.Length*i);

    y := Round(PaintBox2.Height/2 + PaintBox2.Height/2*FastFourier1.Inverse[i,cpRe]);

    PaintBox2.Canvas.LineTo(x,y);

  end;

end;